

import java.util.*;

public class CollectionTest {
    public static void main(String[] args) {


       /* l.add(1);
        l.add(2);
        l.add(3);
        l.add(4);
        Iterator it = l.iterator();
        System.out.println("目前:"+l.size());
        //it.remove();
        while (it.hasNext()) {
            System.out.println(it.next());

        }
        System.out.println("删除后："+ l.size());
        int [] arr = {1,2,3,4,5,6};
        for (int data:arr) {
            System.out.println(data);
        }*/
        List<String> l = new LinkedList<>();
        l.add("你好啊");
        l.add("我是你爹");
        l.add("你是我儿");

        for(String o:l) {
            System.out.println(o);
        }
        People<String> p = new People<>("abc","basd");
        System.out.println("地址："+p.getAddress()+" 姓名："+p.getName());
        //get()
        System.out.println(l.get(2));
        //indexOf（）
        System.out.println(l.indexOf("我是你爹"));
        //remove(int x)
        l.remove(2);
        System.out.println(l.size());
        //Iterator  = l.iterator();
        System.out.println(l.lastIndexOf("我是你爹"));
        System.out.println("===============================================================");
        Map<Integer,String > map = new HashMap<>();
        map.put(1,"黄纪元");
        map.put(2,"张亮");
        map.put(3,"李泉州");
        map.put(4,"刘正伟");
        String s = map.get(3);
        System.out.println(s);
        System.out.println(map.keySet());
        System.out.println(map.values());
        System.out.println("map中元素个数：" + map.size());

        //System.out.println(map.remove(1));
        System.out.println("按key删除一个元素后："+map.size());
        System.out.println("now map："+map.values());
        System.out.println("是否包含黄纪元：" + map.containsValue("黄纪元"));
        System.out.println("是否包含张亮：" + map.containsValue("张亮"));
        System.out.println("按key“3” ？：" + map.containsKey(3));
        //map.clear();
        System.out.println("now size:" + map.size());
        Set<Integer> key = map.keySet();
        Iterator<Integer> it = key.iterator();
        while (it.hasNext()) {

            Integer i = it.next();
            String values = map.get(i);
            System.out.println(i+"="+values);
        }
        System.out.println("======================================");
        //用增强for循环
        for(Integer o:key) {
            System.out.println(o+"="+map.get(o));

        }
        System.out.println("===============================");
        //使用enTrySet
        Set<Map.Entry<Integer,String >> set = map.entrySet();
        for (Map.Entry x:set) {
            System.out.println(x);

        }
        System.out.println("================================");

        Iterator<Map.Entry<Integer,String>> it1 = set.iterator();
        while (it1.hasNext()) {
          Map.Entry<Integer,String> ele = it1.next();
          Integer key1 = ele.getKey();
          String values = ele.getValue();
            System.out.println(key1+"="+values);
            //System.out.println(ele);

            System.out.println("===============================");
            for (Map.Entry<Integer,String> node:set) {
                System.out.println(node.getKey()+"="+node.getValue());
            }

        }






    }


}
class People<E> {
    private E name;
    private E address;

    public E getName() {
        return name;
    }

    public void setName(E name) {
        this.name = name;
    }

    public E getAddress() {
        return address;
    }

    public void setAddress(E address) {
        this.address = address;
    }

    public People(E name, E address) {
        this.name = name;
        this.address = address;
    }

    public People() {
    }
}

